﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;
using System.Collections.Generic;

public partial class Evaluate_CheckNewD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "320401"))
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["CheckID"] == null)
            {
                ActionTitle.Text = "添加考核验收项目";
            }
            else
            {
                ActionTitle.Text = "编辑考核验收项目";
                BindData();
            }
        }
    }

    private void BindData()
    {
        CheckInfo check = Check.GetCheck(int.Parse(Request.QueryString["CheckID"]));
        CheckName.Text = check.CheckName;
        CheckDate.Text = check.CheckDate.ToShortDateString();
        TotalScore.Text = check.TotalScore.ToString("#");
        Description.Text = check.Description;
        rbType.SelectedValue = check.Flag.ToString();
        rbType.Enabled = false;
    }
    private void Insert()
    {
        CheckInfo check = new CheckInfo();
        check.CheckName = CheckName.Text;
        check.CheckDate = DateTime.Parse(CheckDate.Text);
        check.TotalScore = decimal.Parse(TotalScore.Text);
        check.Description = Description.Text;
        check.DepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 6) + "0";
        check.Flag = Convert.ToInt32(rbType.SelectedValue);
        int checkID = Check.Insert(check);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "添加考核验收项目";
        log.ItemID = checkID.ToString();
        log.ItemName = "Checks";
        log.ItemFullUrl = "CheckNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：添加成功！";
    }
    private void Update()
    {
        CheckInfo check = Check.GetCheck(int.Parse(Request.QueryString["CheckID"]));
        check.CheckName = CheckName.Text;
        check.CheckDate = DateTime.Parse(CheckDate.Text);
        check.TotalScore = decimal.Parse(TotalScore.Text);
        check.Description = Description.Text;
        check.Flag = Convert.ToInt32(rbType.SelectedValue);
        Check.Update(check);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "更新考核验收项目";
        log.ItemID = Request.QueryString["CheckID"];
        log.ItemName = "Checks";
        log.ItemFullUrl = "CheckNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：更新成功！";
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["CheckID"] == null)
                Insert();
            else
                Update();
        }
        catch (Exception ex)
        {
            Prompt.Text = "错误：" + ex.Message;
        }
    }
}
